#!/bin/bash

set -e          # exit on error
set -o pipefail # exit on pipeline error
set -u          # treat unset variable as error

. /minioslib || exit 1

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

LNG="$(echo $LOCALE | cut -d_ -f1)"

pkg update

# install packages
#!!!the name of the main application of the module must be specified in the first line of package.list!!!
if [ -f "$SCRIPT_DIR/package.list" ]; then
    install_packages --package-list "$SCRIPT_DIR/package.list"
    PACKAGE=$(head -n 1 "$SCRIPT_DIR/package.list")
    echo "PACKAGE=$PACKAGE" >/.package
    echo "VERSION=$(dpkg -s $PACKAGE | grep Version | sed 's/Version: //g' | sed 's/:/-/g')" >>/.package
fi

if [ $LOCALE != "en_US" ]; then
    if [ "$LOCALE" = "pt_BR" ] || [ "$LOCALE" = "zh_CN" ] || [ "$LOCALE" = "zh_TW" ]; then
        sed -i "s/doublecmd.en.po/doublecmd.$LOCALE.po/g" /etc/skel/.config/doublecmd/doublecmd.xml
    else
        sed -i "s/doublecmd.en.po/doublecmd.$LNG.po/g" /etc/skel/.config/doublecmd/doublecmd.xml
    fi
fi
